import { ArchiveDepts } from './archiveDept';
let _ArchiveDepts = ArchiveDepts;
/**
 * 拷贝下面两行到 mock/index.js中,即可支持客户端虚拟数据、免服务端连接
 * import ArchiveDeptMock from './mdp/arc/archiveDeptMock';
 * ArchiveDeptMock.bootstrap(mock);
 */
export default {
  /**
   * mock bootstrap
   */
  bootstrap(mock) {    
  
    //获取列表 模糊查询、根据关键字查询
    mock.onGet('/mdp/arc/archiveDept/listKey').reply(config => {
      let params = config.params;
      let mockArchiveDepts = _ArchiveDepts.filter(archiveDept => {
      	if(params.id||params.id==''){ if( archiveDept.id.indexOf(params.id)>=0) return true;}
      	if(params.archiveId||params.archiveId==''){ if( archiveDept.archiveId.indexOf(params.archiveId)>=0) return true;}
      	if(params.deptid||params.deptid==''){ if( archiveDept.deptid.indexOf(params.deptid)>=0) return true;}
      	if(params.canRead||params.canRead==''){ if( archiveDept.canRead.indexOf(params.canRead)>=0) return true;}
      	if(params.canEdit||params.canEdit==''){ if( archiveDept.canEdit.indexOf(params.canEdit)>=0) return true;}
      	if(params.canDown||params.canDown==''){ if( archiveDept.canDown.indexOf(params.canDown)>=0) return true;}
      	if(params.canDel||params.canDel==''){ if( archiveDept.canDel.indexOf(params.canDel)>=0) return true;}
      	if(params.remark||params.remark==''){ if( archiveDept.remark.indexOf(params.remark)>=0) return true;}
      	if(params.endDate||params.endDate==''){ if( archiveDept.endDate.indexOf(params.endDate)>=0) return true;}
      	if(params.encryptType||params.encryptType==''){ if( archiveDept.encryptType.indexOf(params.encryptType)>=0) return true;}
      	if(params.includeSubDept||params.includeSubDept==''){ if( archiveDept.includeSubDept.indexOf(params.includeSubDept)>=0) return true;}
      	if(params.isSendEmail||params.isSendEmail==''){ if( archiveDept.isSendEmail.indexOf(params.isSendEmail)>=0) return true;}
      	if(params.isSendWeixin||params.isSendWeixin==''){ if( archiveDept.isSendWeixin.indexOf(params.isSendWeixin)>=0) return true;}
      	if(params.isSendOa||params.isSendOa==''){ if( archiveDept.isSendOa.indexOf(params.isSendOa)>=0) return true;}
      	if(params.isSendShortMsg||params.isSendShortMsg==''){ if( archiveDept.isSendShortMsg.indexOf(params.isSendShortMsg)>=0) return true;}
      	if(params.createDate||params.createDate==''){ if( archiveDept.createDate.indexOf(params.createDate)>=0) return true;}
      	if(params.sendDate||params.sendDate==''){ if( archiveDept.sendDate.indexOf(params.sendDate)>=0) return true;}
        return false;
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            data: mockArchiveDepts
          }]);
        }, 1000);
      });
    });
    
    

    //获取列表（分页/不分页）
    mock.onGet('/mdp/arc/archiveDept/list').reply(config => {
      let params = config.params;
      let mockArchiveDepts = _ArchiveDepts.filter(archiveDept => {
      	var isTrue=false;
      	if(params.id||params.id==''){if(archiveDept.id.indexOf(params.id)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.archiveId||params.archiveId==''){if(archiveDept.archiveId.indexOf(params.archiveId)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.deptid||params.deptid==''){if(archiveDept.deptid.indexOf(params.deptid)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.canRead||params.canRead==''){if(archiveDept.canRead.indexOf(params.canRead)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.canEdit||params.canEdit==''){if(archiveDept.canEdit.indexOf(params.canEdit)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.canDown||params.canDown==''){if(archiveDept.canDown.indexOf(params.canDown)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.canDel||params.canDel==''){if(archiveDept.canDel.indexOf(params.canDel)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.remark||params.remark==''){if(archiveDept.remark.indexOf(params.remark)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.endDate||params.endDate==''){if(archiveDept.endDate.indexOf(params.endDate)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.encryptType||params.encryptType==''){if(archiveDept.encryptType.indexOf(params.encryptType)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.includeSubDept||params.includeSubDept==''){if(archiveDept.includeSubDept.indexOf(params.includeSubDept)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isSendEmail||params.isSendEmail==''){if(archiveDept.isSendEmail.indexOf(params.isSendEmail)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isSendWeixin||params.isSendWeixin==''){if(archiveDept.isSendWeixin.indexOf(params.isSendWeixin)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isSendOa||params.isSendOa==''){if(archiveDept.isSendOa.indexOf(params.isSendOa)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isSendShortMsg||params.isSendShortMsg==''){if(archiveDept.isSendShortMsg.indexOf(params.isSendShortMsg)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.createDate||params.createDate==''){if(archiveDept.createDate.indexOf(params.createDate)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.sendDate||params.sendDate==''){if(archiveDept.sendDate.indexOf(params.sendDate)>=0){isTrue=true;}else{isTrue=false;}}
      	return isTrue;
	  });
      if(!config.params.currentPage){ 
	      return new Promise((resolve, reject) => {
	        setTimeout(() => {
	          resolve([200, {
	            data: mockArchiveDepts
	          }]);
	        }, 1000);
	      });
      }
    
      let {pageSize,currentPage, total} = config.params;
      total = mockArchiveDepts.length;
      mockArchiveDepts = mockArchiveDepts.filter((archiveDept, index) => index < pageSize * currentPage && index >= pageSize * (currentPage - 1));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            pageInfo: {
            	total:total
            },
            data: mockArchiveDepts,
            tips:{
            	isOk:true,
            	msg:'查询成功'
            }
          }]);
        }, 1000);
      });
    });

    //删除
    mock.onPost('/mdp/arc/archiveDept/del').reply(config => {
      var params = JSON.parse( config.data );
      let {  id  } = params;
      _ArchiveDepts = _ArchiveDepts.filter(archiveDept => archiveDept.id !== id);
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //批量删除
    mock.onPost('/mdp/arc/archiveDept/batchDel').reply(config => {
      var params = JSON.parse( config.data );
      _ArchiveDepts = _ArchiveDepts.filter(archiveDept => !params.includes(archiveDept.id));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
           tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //编辑
    mock.onPost('/mdp/arc/archiveDept/edit').reply(config => {
      var params = JSON.parse( config.data );
      let { id,archiveId,deptid,canRead,canEdit,canDown,canDel,remark,endDate,encryptType,includeSubDept,isSendEmail,isSendWeixin,isSendOa,isSendShortMsg,createDate,sendDate } = params;
      _ArchiveDepts.some(archiveDept => {
        if (archiveDept.id === id) {
			archiveDept.id = id;
			archiveDept.archiveId = archiveId;
			archiveDept.deptid = deptid;
			archiveDept.canRead = canRead;
			archiveDept.canEdit = canEdit;
			archiveDept.canDown = canDown;
			archiveDept.canDel = canDel;
			archiveDept.remark = remark;
			archiveDept.endDate = endDate;
			archiveDept.encryptType = encryptType;
			archiveDept.includeSubDept = includeSubDept;
			archiveDept.isSendEmail = isSendEmail;
			archiveDept.isSendWeixin = isSendWeixin;
			archiveDept.isSendOa = isSendOa;
			archiveDept.isSendShortMsg = isSendShortMsg;
			archiveDept.createDate = createDate;
			archiveDept.sendDate = sendDate
          return true;
        }
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'编辑成功'
            }
          }]);
        }, 500);
      });
    });

    //新增
    mock.onPost('/mdp/arc/archiveDept/add').reply(config => {
      var params = JSON.parse( config.data );
      let { id,archiveId,deptid,canRead,canEdit,canDown,canDel,remark,endDate,encryptType,includeSubDept,isSendEmail,isSendWeixin,isSendOa,isSendShortMsg,createDate,sendDate } = params;
      _ArchiveDepts.push({
		id:id,
		archiveId:archiveId,
		deptid:deptid,
		canRead:canRead,
		canEdit:canEdit,
		canDown:canDown,
		canDel:canDel,
		remark:remark,
		endDate:endDate,
		encryptType:encryptType,
		includeSubDept:includeSubDept,
		isSendEmail:isSendEmail,
		isSendWeixin:isSendWeixin,
		isSendOa:isSendOa,
		isSendShortMsg:isSendShortMsg,
		createDate:createDate,
		sendDate:sendDate
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'新增成功'
            }
          }]);
        }, 500);
      });
    });

  }
};